<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %> 
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>系统权限资源列表</title>
<link href="${ctx }/css/ztreeStyle.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/js/layui/css/layui.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/css/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/css/ajax_tip.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/js/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="${ctx}/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctx}/js/common.js"></script>
<script type="text/javascript" src="${ctx }/js/ztree/jquery.ztree.core-3.5.js"></script>
<style>
	.formtitle{
		height: 29px;
		margin-bottom: 8px;
	}
	.listBtnDiv{
		margin-top: -8px;
		margin-right: 0px;
	}
	.leftTreeDiv{
		width: 220px;
		float: left;
		margin: 10px;
		padding: 10px;
		margin-top: 0px;
		margin-right: 0px;
		padding-top:3px;
	}
	.zTreeDemoBackground{
		width: 210px;
		height: 100%;
		overflow: auto;
	}
</style>
</head>
<body>
<div class="listNavTitle">
	<p>
		<label>系统管理 ></label>
		<label>权限管理</label>
	</p>
</div>
<div class="rightinfo" >
	<div class="formtitle">
		<span id="parentSpanName">当前选择父级资源    顶级资源</span>
		<div class="listBtnDiv">
			<shiro:hasPermission name="sysman:SYSTEM_AUTH_MAN:add">
				<button id="add" class="layui-btn layui-btn-normal" title="button">新增资源</button>
			</shiro:hasPermission>
		</div>
	</div>
	<div class="leftTreeDiv">
		<table class="tablelist">
			<thead>
			<tr>
				<th>权限资源图</th>
			</tr>
			</thead>
			<tbody>
			<tr>
				<td>
					<div class="zTreeDemoBackground left">
						<ul id="treeDemo" class="ztree"></ul>
					</div>
				</td>
			</tr>
			</tbody>
		</table>
	</div>
	<form id="searchForm" style="display:none;">
	  <ul class="search_forminfo">
	    <li style="float:right;">
	      <label>&nbsp;</label>
	      <input type="hidden" name="authParentCode" id="authParentCode" value="0"/>
	    </li>
	  </ul>
  </form>
  <div id="pageList" style="float:left;margin-left:10px;clear: none;">
  	
  </div>
</div>
</body>
</html>
<script type="text/javascript" src="${ctx }/js/layui/layui.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    var moduleType = '${bo.moduleType}';

	initUrl('${ctx}/sysman/authResource/toAuthResourceList.do?moduleType=${bo.moduleType}','','${ctx}/sysman/authResource/toChangeView.do?moduleType=${bo.moduleType}','${ctx}/sysman/authResource/delSystemAuthResource.do');

	baseSearchQuery(1);	
	
	$("#add").click(function(){
		if(panIsNull(parentId)){
			parentId = 0;
		}
		var url = "${ctx}/sysman/authResource/addSystemAuthResource.do?moduleType="+moduleType+"&parentCode="+parentId;
		var baseAdd = layer.open({
	        type: 2,
	        title: false,
	        shadeClose: true,
	        shade: false,
	        maxmin: true, //开启最大化最小化按钮
	        area: ['930px' , '530px'],
	        content: url
	    });
		layer.full(baseAdd);
	});
	
	$("#del").click(function(){
  		baseDel();
	});
	
	$("#toEdit").click(function(){
  		toBaseEdit(false,930,530,true);
	});

	$(".zTreeDemoBackground").height($(window).height()-210);
    $("#pageList").width($(window).width()-300);
    $(".rightinfo").height($(window).height()-80);
	onloadNav();
});

	var parentId = 0;
	var authResourceList = ${authResourceList};
	// 加载权限资源图数据
	function onloadNav(){
		var setting = {
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				beforeClick: beforeClick,
				onClick: onClick
			}
		};
		if(panIsNull(authResourceList)){
			layer.alert('权限资源图数据暂无数据');
			return;
		}
		var jsondata="[";
		for(var i = 0;i<authResourceList.length;i++){
			jsondata+="{'pId':'"+authResourceList[i].authparentCode+"','id':'"+authResourceList[i].authCode+"','name':'"+authResourceList[i].authName+"'},"
		}
		jsondata = jsondata.substring(0,jsondata.length-1);
		jsondata+="]";
		jsondata=eval(jsondata);
		$.fn.zTree.init($("#treeDemo"), setting, jsondata);
	}
	
	function beforeClick(treeId, treeNode, clickFlag) {
		//alert(treeId + "--" + treeNode + "--" +clickFlag);
	}
	
	function onClick(event, treeId, treeNode, clickFlag) {
		parentId = treeNode.id;
		$("#authParentCode").val(treeNode.id);
		$("#parentSpanName").text('当前选择父级权限资源  ' + treeNode.name);
		baseSearchQuery(1);
	}
</script>